package sbpme.designer.policy;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gef.requests.ReconnectRequest;

import sbpme.designer.command.TransitionCreateCommand;
import sbpme.designer.command.TransitionReconnectSourceCommand;
import sbpme.designer.command.TransitionReconnectTargetCommand;
import sbpme.designer.model.Activity;
import sbpme.designer.model.Transition;
import sbpme.designer.parts.ActivityPart;


public class ActivityGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy {

	@Override
	protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
		TransitionCreateCommand cmd = (TransitionCreateCommand) request.getStartCommand();
		cmd.setTarget(getActivity());
		return cmd;
	}

	@Override
	protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
		TransitionCreateCommand cmd = new TransitionCreateCommand();
		cmd.setSource(getActivity());
		request.setStartCommand(cmd);
		return cmd;
	}

	@Override
	protected Command getReconnectSourceCommand(ReconnectRequest request) {
		TransitionReconnectSourceCommand cmd = new TransitionReconnectSourceCommand();
		cmd.setTransition((Transition) request.getConnectionEditPart().getModel());
		cmd.setSource(getActivity());
		return cmd;
	}

	@Override
	protected Command getReconnectTargetCommand(ReconnectRequest request) {
		TransitionReconnectTargetCommand cmd = new TransitionReconnectTargetCommand();
		cmd.setTransition((Transition) request.getConnectionEditPart().getModel());
		cmd.setTarget(getActivity());
		return cmd;
	}

	protected ActivityPart getActivityPart() {
		return (ActivityPart) getHost();
	}

	protected Activity getActivity() {
		return (Activity) getHost().getModel();
	}

}
